package com.aotain.hbase;

import java.io.IOException;
import java.util.ArrayList;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.exceptions.DeserializationException;
import org.apache.hadoop.hbase.filter.BinaryComparator;
import org.apache.hadoop.hbase.filter.ByteArrayComparable;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.FilterBase;
import org.apache.hadoop.hbase.filter.ParseFilter;
import org.apache.hadoop.hbase.filter.RegexStringComparator;
import org.apache.hadoop.hbase.filter.SingleColumnValueFilter;
import org.apache.hadoop.hbase.filter.SubstringComparator;
import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
import org.apache.hadoop.hbase.filter.Filter.ReturnCode;
import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
import org.apache.hadoop.hbase.protobuf.generated.FilterProtos;
import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos;
import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.CompareType;
import org.apache.hadoop.hbase.util.ByteStringer;
import org.apache.hadoop.hbase.util.Bytes;

import com.google.common.base.Preconditions;
import com.google.protobuf.InvalidProtocolBufferException;

public class CustomSingleColumnValueFilter extends SingleColumnValueFilter {
	static final Log LOG = LogFactory.getLog(CustomSingleColumnValueFilter.class);
	
	private long pageSize = Long.MAX_VALUE;
	private int rowsAccepted = 0;
	  
	public CustomSingleColumnValueFilter(byte[] family, byte[] qualifier,
			CompareOp compareOp, byte[] value, long pageSize) {
		super(family, qualifier, compareOp, value);
		pageSize = pageSize;
		// TODO Auto-generated constructor stub
	}
	
	public boolean filterRow() {
	    this.rowsAccepted++;
	    if(this.rowsAccepted > this.pageSize)
	    	return true;
	    return this.foundColumn? !this.matchedColumn: this.filterIfMissing;
	}

	

}
